package com.woniuxy02;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Test07 {

    public static void main(String[] args) {

        try {
            String str = "aaa-1-1";
            Date date = stringToDate(str);
            System.out.println(date);
        } catch (StringToDateConvertException e) {
            System.out.println(e.getMessage());
        }

        System.out.println("程序结束");
    }

    private static Date stringToDate(String str) {
        try {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date date = df.parse(str);
            return date;
        } catch (Exception e) {
            e.printStackTrace();
            throw new StringToDateConvertException("日期格式错误，无法转换");
        }
    }
}
